package test6;

import java.util.LinkedList;
import java.util.ListIterator;

public class TestMain {
    public static void main(String[] args) {

        LinkedList<Shop> shopList = new LinkedList<>();
        // 添加多个商品对象到集合中
        shopList.add(new Shop(1, "手机", 3200));
        shopList.add(new Shop(2, "电脑", 7200));
        shopList.add(new Shop(3, "方便面", 30));

        // 查看商品的数量
        int nums = 0;
        // 遍历所有商品的信息
        ListIterator it = shopList.listIterator();
        while (it.hasNext()) {
            System.out.println(it.next());
            nums++;
        }
        System.out.println("商品数量： " + nums);

        // 删除集合中部分商品的元素
        shopList.remove(2);
        // 判断集合中是否包含指定商品
        String shopName = "方便面";
        boolean bool = false;
        for (int i = 0; i < nums - 1; i++) {
            if (shopName.equals(shopList.get(i).getName())) {
                bool = true;
                break;
            }
        }
        if (bool){
            System.out.println("包含该商品");
        }else {
            System.out.println("不包含该商品");
        }
    }
}
